package com.vspush.udp.core;

import com.vspush.manage.MessageHeadle;
import com.vspush.manage.type.MesssageType;
import com.vspush.udp.handle.LiveHeadle;
import com.vspush.udp.handle.StartHeadle;

public class EncodeMessage  {
	
	
		private MesssageType mtype;
		
		private String msg;
		
		private MessageHeadle  messageHeadle;
	   

		public EncodeMessage(String msg){
			if(msg.startsWith(MesssageType.error.getName())){
				this.mtype = MesssageType.error;
			}
			if(msg.startsWith(MesssageType.login.getName())){
				this.mtype = MesssageType.login;
			}
			if(msg.startsWith(MesssageType.msg.getName())){
				this.mtype = MesssageType.msg;
				messageHeadle =new  MessageHeadle(msg.substring(MesssageType.msg.getName().length()));
			}
			if(msg.startsWith( MesssageType.start.getName())){
				this.mtype = MesssageType.start;
				messageHeadle =new  StartHeadle(msg.substring(MesssageType.start.getName().length()));
				
			}
			if(msg.startsWith(MesssageType.un.getName())){
				this.mtype = MesssageType.un;
			}
			if(msg.startsWith(MesssageType.ok.getName())){
				this.mtype = MesssageType.ok;
			}
			if(msg.startsWith(MesssageType.live.getName())){
				this.mtype = MesssageType.live;
				messageHeadle =new  LiveHeadle(msg.substring(MesssageType.live.getName().length()));
			}
			if(messageHeadle==null){
				messageHeadle =new  MessageHeadle(msg);
			}
		}


		public MesssageType getMtype() {
			return mtype;
		}


		public String getMsg() {
			return msg;
		}


		public MessageHeadle getMessageHeadle() {
			return messageHeadle;
		}


		
		

}
